package edu.pk.mc.breakthebrick;

import android.os.Bundle;
import android.os.Handler;
import android.os.Messenger;
import android.app.ListActivity;
import android.content.ContentValues;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.view.Menu;
import android.view.View;
import android.widget.SimpleCursorAdapter;

public class HighScoreActivity extends ListActivity {
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_high_score);

//		Intent i = new Intent(this,ScoreInfoService.class);
//		Messenger m = new Messenger(mHandler);
//		i.putExtra("m", m);
//		startService(i);
	
//		private Handler mHandler = new Handler(){
//			public void handleMessage(android.os.Message msg) {
//
//				ScoreDTO [] data = (ScoreDTO [])msg.obj;
//				for(int i=0;i<data.length;i++)
//				{
//					SQLiteDatabase db = new MySQLiteOpenHelper(getBaseContext()).getWritableDatabase();
//					ContentValues values = new ContentValues();
//					values.put(SQLDemoContract.tables.HighScoreEntry.COLUMN_NAME_SCORE, data[i].score);
//					db.insert(SQLDemoContract.tables.HighScoreEntry.TABLE_NAME, null, values);
//				}
		SQLiteDatabase db = new MySQLiteOpenHelper(getBaseContext()).getReadableDatabase();
		String table = SQLDemoContract.tables.HighScoreEntry.TABLE_NAME;
		String [] columns = {SQLDemoContract.tables.HighScoreEntry._ID, SQLDemoContract.tables.HighScoreEntry.COLUMN_NAME_SCORE};
		String selection = null;
		String [] selectionArgs = null;
		String groupBy = null;
		String having = null;
		String orderBy = null;
		Cursor c = db.query(table  , columns, selection, selectionArgs, groupBy, having, orderBy+" DESC LIMIT 5" );
		int [] to = {android.R.id.text1};
		String [] from = { SQLDemoContract.tables.HighScoreEntry.COLUMN_NAME_SCORE};
		SimpleCursorAdapter sca = new SimpleCursorAdapter(getBaseContext(), android.R.layout.simple_list_item_1, c, from, to, SimpleCursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
		setListAdapter(sca);
}
//			}
//	};
	public void goBack(View v){
		Intent i = new Intent();
		//i.putExtra("result", "hello world");
		setResult(RESULT_OK, i);
		finish();
	}
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.high_score, menu);
		return true;
	}
}

	